package com.showcai.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.showcai.dao.CertificateClassifyMapper;
import com.showcai.module.CertificateClassify;
import com.showcai.module.Distributor;
import com.showcai.myRunTime.MyRunTimeExcption;
import com.showcai.service.CertificateClassifyService;
import com.showcai.service.ServiceBase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by Baggio on 2018-9-15.
 */
@Service
public class CertificateClassifyServiceImpl extends ServiceBase implements CertificateClassifyService {
    @Autowired
    CertificateClassifyMapper certificateClassifyMapper;

    @Override
    public List<CertificateClassify> getCertificateClassifyList(Map<String, String> map) throws MyRunTimeExcption {
        return certificateClassifyMapper.getCertificateClassifyList(map);
    }

    @Override
    public CertificateClassify selectCertificateClassifyById(Long tid) throws MyRunTimeExcption {
        return certificateClassifyMapper.selectCertificateClassifyById(tid);
    }

    @Override
    public CertificateClassify selectCertificateClassifyByProductEntityId(Long productEntityId) throws MyRunTimeExcption {
        return certificateClassifyMapper.selectCertificateClassifyByProductEntityId(productEntityId);
    }

    @Override
    public PageInfo getPageInfoCertificateClassifyList(Map<String, String> map) throws MyRunTimeExcption {
        Integer page = Integer.parseInt(map.get("page"));
        Integer pageSize = Integer.parseInt(map.get("pageSize"));
        PageHelper.startPage(page, pageSize);
        List<CertificateClassify> certificateClassifyList = certificateClassifyMapper.getCertificateClassifyList(map);
        PageInfo<CertificateClassify> pageinfo = new PageInfo<>(certificateClassifyList);
        return pageinfo;
    }

    @Override
    public void ModifyCertificateClassify(CertificateClassify certificateClassify) throws MyRunTimeExcption {
        if (certificateClassify.getTid() == null) {
            certificateClassify.setCreateTime(new Date());
            certificateClassifyMapper.insertCertificateClassify(certificateClassify);
            return;
        }
        certificateClassifyMapper.updateCertificateClassifyByPrimaryKeySelective(certificateClassify);

    }
}
